package br.com.virtual.base.controller.vender;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import br.com.virtual.base.controller.util.VirtualMB;
import br.com.virtual.vender.model.Venda;
import br.com.virtual.vender.service.VendaService;

@ManagedBean @ViewScoped
public class VendaFinalizadaMB extends VirtualMB {

	private static final long serialVersionUID = 1L;

	private Venda venda;
	@EJB private VendaService vendaService;
	
	@PostConstruct
	private void init(){
		
		if(this.hasUsuarioAutenticado()){
			setVenda((Venda)this.getFlash(Venda.class.getName()));
			
			if( !isNull(venda))
				setVenda(this.vendaService.read(venda.getId()));
			else
				this.redirectToIndex();
		}else
			this.verificaAutenticacao();
	}

	public Venda getVenda() {
		return venda;
	}

	public void setVenda(Venda venda) {
		this.venda = venda;
	}
	
	
}
